package container;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ContainerSingleton {

    private final static Map<String, Object> CONTAINER = new ConcurrentHashMap<>();

    private ContainerSingleton() {

    }

    public synchronized final static Object getInstance(String name) {
        if(!CONTAINER.containsKey(name)) {
            Object o = null;
            try {
                Class<?> clazz = Class.forName(name);
                o = clazz.newInstance();
                CONTAINER.put(name, o);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return o;
        } else {
            return CONTAINER.get(name);
        }
    }
}
